package com.tedu.egmvc.controller;

import com.tedu.egmvc.mapper.AddressMapper;
import com.tedu.egmvc.pojo.dto.AddressDTO;
import com.tedu.egmvc.pojo.entity.Address;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "邮箱模块")
@Controller
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @PostMapping("Address/insert")
    @ResponseBody
    @ApiOperation("邮箱添加功能")
    public String reg(AddressDTO addressDTO){
        int num = addressMapper.insertAddress(addressDTO);
        return num>0?"添加成功":"添加失败";
    }
    @ApiOperation("邮箱查询功能")
    @GetMapping("Address/select")
    @ResponseBody
    public List<Address> select(){
        List<Address> addressList = addressMapper.selectAddress();
        return addressList;
    }
    @ApiOperation("邮箱删除功能")
    @DeleteMapping("Address/delete")
    @ResponseBody
    @ApiImplicitParam(name = "id",value = "地址ID",required = true,dataType = "Integer",example = "3")
    public String delect(Integer id){
        int num = addressMapper.deleteAddress(id);
        return num>0?"删除成功":"删除失败";
    }
    @ApiOperation("邮箱修改功能")
    @PutMapping("Address/update")
    @ResponseBody
    public String update(Address address){
        int num = addressMapper.updateAddress(address);
        return num>0?"修改成功":"修改失败";
    }
}
